package uit.edu.vn.Activity;

import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

public class SMSRestoreActivity extends TabActivity {
    private String username = "";
    private String password = "";
    private static final String STRING_NAME_USERSETTING = "USER REFERENCES";
    private SharedPreferences ShareRef = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_tabview);
        username = getSetting("username");
        password = getSetting("password");
	      //kiem tra neu username va password rong thi ket thuc activity hien tai va goi activity login
	      if(username.equals("") && password.equals("")){
	          Intent intent = new Intent(SMSRestoreActivity.this, LoginActivity.class);
	          startActivity(intent);
	          this.finish();            	
	      }		
		Resources res = getResources(); 
        TabHost tabHost= getTabHost();
        TabHost.TabSpec spec;
        // Tạo intent và gọi các class tiep theo
        Intent i;
        //goi ContactRestoreSDCardActivity.class
        i= new Intent().setClass(this,SmsRestoreSDCardActivity.class);
        spec= tabHost.newTabSpec("").setIndicator(getResources().getString(R.string.txt_Sdcard),res.getDrawable(R.drawable.tab_restore_sdcard_seletor)).setContent(i);
        tabHost.addTab(spec);
        // goi ContactRestoreServerActivity.class
        i= new Intent().setClass(this, SmsRestoreServerActivity.class);
        spec= tabHost.newTabSpec("").setIndicator(getResources().getString(R.string.txt_Server),res.getDrawable(R.drawable.tab_restore_selector)).setContent(i);
        tabHost.addTab(spec);
        tabHost.setCurrentTab(0);   
	}
	public String getSetting(String key) {
        ShareRef = getSharedPreferences(STRING_NAME_USERSETTING, Context.MODE_WORLD_WRITEABLE);
        return ShareRef.getString(key, "");
	}
}
